/******************************************************************************
** $Id: dc_dbgmon_api.h,v 1.2 2009-03-25 01:09:43 rayskymy Exp $
**                 Proprietary and Confidential Information                  **
**                                                                           **
**                 Copyright (c) SigmaTel, Inc. Unpublished                  **
**                                                                           **
** This source code and the algorithms implemented therein constitute        **
** confidential information and may compromise trade secrets of SigmaTel,    **
** Inc. or its associates, and any unauthorized use thereof is prohibited.   **
**                                                                           **
******************************************************************************/
#ifndef _dc_dbgmon_api_h_
# define _dc_dbgmon_api_h_

# define DC_DBGMON_EXPORT_SYMBOL_AS(_name, _cb)
# define DC_DBGMON_EXPORT_ARRAY_AS(_name, _cb)
# define DC_DBGMON_EXPORT_NVRAM_AS(_name, _cb)
# define DC_DBGMON_EXPORT_DBGEXT_AS(_name, _cb)
# define DC_DBG_EXPORT_SYMBOL(_cb) DC_DBGMON_EXPORT_SYMBOL_AS(#_cb, _cb)
# define DC_DBG_EXPORT_ARRAY(_cb) DC_DBGMON_EXPORT_ARRAY_AS(#_cb, _cb)
# define DC_DBG_EXPORT_NVRAM(_cb) DC_DBGMON_EXPORT_NVRAM_AS(#_cb, _cb)
# define DC_DBG_EXPORT_DBGEXT(_cb) DC_DBGMON_EXPORT_DBGEXT_AS(#_cb, _cb)

#if 0
/**************************************************************************//**
*  @file dc_dbgmon_api.h
*  @brief This file contains the definitions for the DBGmon firmware API.
******************************************************************************/
/******************************************************************************
*  FILE FORMAT: <PUBLIC>
*      1. INCLUDES 
*      2. ENUMERATIONS 
*      3. DEFINES
*      4. STRUCTURES
*      5. GLOBALS
*      6. PUBLIC FUNCTION PROTOTYPES
******************************************************************************/
/******************************************************************************
*  1. INCLUDES
******************************************************************************/
#include "dc_dbgmon_channels.h"

/******************************************************************************
*  2. ENUMERATIONS
******************************************************************************/
typedef enum 
{
    // Exported symbol such as 'C' data structures, integers, etc.
    DC_DBGMON_EXPORT_SYMBOL=1,

    // Symbol being exported resides in non-volatile memory (NVRAM).   
    // This enumeration is treated same as DC_DBGMON_EXPORT_SYMBOL.
    //
    // This enumeration allows for special handling required for 
    // modifying data that is maintained in NVRAM.
    DC_DBGMON_EXPORT_NVRAM=5, 

    // Exported symbol is an array including integer arrays, ?C? data 
    // structure arrays, etc.
    DC_DBGMON_EXPORT_ARRAY=3, 

    // Exported symbol is a pointer to a dbgmon extension dispatch
    // function.  
    DC_DBGMON_EXPORT_DBGEXT=6, 

    // For INTERNAL use only
    //
    // Used internally by the system for exporting the Version 
    // information. 
    DC_DBGMON_EXPORT_VERSION=0,

    // For INTERNAL use only
    //
    // Used internally to indicate to DBGmon that the end of list of 
    // exported symbols has been reached.
    DC_DBGMON_EXPORT_EOL=2,

    // For INTERNAL use only
    //
    // Used internally to indicate to DBGmon that the end of list of 
    // exported symbols has been reached and the target system ran
    // out of space to store symbols.
    DC_DBGMON_EXPORT_SHORT_EOL=4

} DC_DBGMON_EXPORT_t; 
/******************************************************************************
*  3. DEFINES
******************************************************************************/
// Version of the DBGmon Configuration Structure called DC_DBGMON_PARAMETERS_t
# define DC_DBGMON_CONFIG_VERSION 3

// Use dc_dbgmon_symbol_export() with a macro
# define DC_DBGMON_EXPORT_SYMBOL_AS(_name, _cb) dc_dbgmon_symbol_export(_name, \
                                                                        DC_DBGMON_EXPORT_SYMBOL, \
                                                                        sizeof(_cb), \
                                                                        0, \
                                                                        (void*)&(_cb))

// Use dc_dbgmon_symbol_export() with a macro
# define DC_DBGMON_EXPORT_ARRAY_AS(_name, _cb) dc_dbgmon_symbol_export(_name, \
                                                                        DC_DBGMON_EXPORT_ARRAY, \
                                                                        sizeof(_cb), \
                                                                        sizeof((_cb)[0]), \
                                                                        (void*)&(_cb))

// Use dc_dbgmon_symbol_export() with a macro
# define DC_DBGMON_EXPORT_NVRAM_AS(_name, _cb) dc_dbgmon_symbol_export(_name, \
                                                                       DC_DBGMON_EXPORT_NVRAM, \
                                                                       sizeof(_cb), \
                                                                       0, \
                                                                       (void*)&(_cb))


// Use dc_dbgmon_symbol_export() with a macro
# define DC_DBGMON_EXPORT_DBGEXT_AS(_name, _cb) dc_dbgmon_symbol_export(_name, \
                                                                       DC_DBGMON_EXPORT_DBGEXT, \
                                                                       0, \
                                                                       0, \
                                                                       (void*)((UINT32)&(_cb)))


// Use dc_dbgmon_symbol_export() with a macro DC_DBGMON_EXPORT_SYMBOL
# define DC_DBG_EXPORT_SYMBOL(_cb) DC_DBGMON_EXPORT_SYMBOL_AS(#_cb, _cb)

// Use dc_dbgmon_symbol_export() with a macro for DC_DBGMON_EXPORT_ARRAY
# define DC_DBG_EXPORT_ARRAY(_cb) DC_DBGMON_EXPORT_ARRAY_AS(#_cb, _cb)

// Use dc_dbgmon_symbol_export() with a macro for DC_DBGMON_EXPORT_NVRAM
# define DC_DBG_EXPORT_NVRAM(_cb) DC_DBGMON_EXPORT_NVRAM_AS(#_cb, _cb)

// Use dc_dbgmon_symbol_export() with a macro for DC_DBGMON_EXPORT_DBGEXT
# define DC_DBG_EXPORT_DBGEXT(_cb) DC_DBGMON_EXPORT_DBGEXT_AS(#_cb, _cb)

// Name for DBGmon flash thread
# define DC_DBGMON_FLASH_THREAD_NAME "dbg_flash"

// Name for DBGmon main thread thread
# define DC_DBGMON_MAIN_THREAD_NAME "dbg_main"

# define DC_DBGMON_IPv4_SV_THREAD_NAME "d_IPv4_SV"
# define DC_DBGMON_IPv4_TX_THREAD_NAME "d_IPv4_TX"
# define DC_DBGMON_IPv4_RX_THREAD_NAME "d_IPv4_RX"


/******************************************************************************
*  4. STRUCTURES
******************************************************************************/
typedef struct
{

    // Customer version
    UINT32 ver_customer;

    // System board version
    UINT16 ver_hw;

    // Size of system DRAM in bytes
    UINT32 ram_size_bytes;

    // Set project name
    char project_name[12];
 
    // Date firmware image was built (maximum length 26)
    char *build_date;

} DC_DBGMON_VERSION_t;

typedef struct
{

    // Version defined from DC_DBGMON_CONFIG_VERSION used
    // for version checking
    UINT32 struct_version;

    DC_DBGMON_VERSION_t version_info;

    // in and out endpoints for USB, if configured for USB
    // USB Device IN endpoint used for DBGmon communication
    UINT32 in_endpoint;
    // USB Device OUT endpoint used for DBGmon communication
    UINT32 out_endpoint;

    // TCP Port number dbgmon will listen on, if configured for IPv4
    UINT16 IPv4_port;

    // Enable restart in boot mode of code. In case of
    // firmware crashes, this can be helpful in capturing
    // "post-mortem" logs.
    boolean restart_boot_mode;
} DC_DBGMON_PARAMETERS_t;

/******************************************************************************
*  5. GLOBALS
******************************************************************************/
/******************************************************************************
*  6. PUBLIC FUNCTION PROTOTYPES
******************************************************************************/
DC_RETURN_CODE dc_dbgmon_setup(DC_DBGMON_PARAMETERS_t *pParams,
                               UINT32 param_size,
                               DC_MEM_PARAMS_t *pMem);

DC_RETURN_CODE dc_dbgmon_init(DC_MEM_PARAMS_t *pMem);


DC_RETURN_CODE dc_dbgmon_thread_get(char *name, 
                                    OSPL_THREAD **thread);


DC_RETURN_CODE dc_dbgmon_flash_init(void);

DC_RETURN_CODE dc_dbgmon_symbol_export(const char *pName,
                                       DC_DBGMON_EXPORT_t type,
                                       UINT32 total_size,
                                       UINT32 element_size,
                                       void *pAddress);

DC_RETURN_CODE dc_dbgmon_reset(void);

#endif

#endif /*  _dc_dbgmon_api_h_ */
